package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.union.cross.CrossUnionModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_CONSTRUCTION_FROM_CROSS, desc = "建设联盟")
public class ConstructUnionCmdFromCross extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        CrossUnionProto.UnionConstructionCrossRespMsg crossRespMsg = CrossUnionProto.UnionConstructionCrossRespMsg.parseFrom(packet.getBytes());

        CrossUnionModule unionModule = player.getModule(CrossUnionModule.class);

        unionModule.handleConstructFromCross(crossRespMsg.getConstructionType(), crossRespMsg.hasConsume() ? crossRespMsg.getConsume() : "", crossRespMsg.getRet());

        UnionProto.UnionConstructionRespMsg.Builder respMsg = UnionProto.UnionConstructionRespMsg.newBuilder();
        respMsg.setRet(crossRespMsg.getRet());
        player.sendPacket(Protocol.U_UNION_CONSTRUCTION, respMsg);

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
